using MeetingManagement.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace MeetingManagement.Infrastructure.EntityConfigurations;

public class MeetingRoomConfiguration : IEntityTypeConfiguration<MeetingRoom>
{
    public void Configure(EntityTypeBuilder<MeetingRoom> builder)
    {
        builder.HasKey(r => r.Id);

        builder.Property(r => r.Name)
            .IsRequired()
            .HasMaxLength(50);

        builder.Property(r => r.Location)
            .HasMaxLength(100);

        builder.Property(r => r.Description)
            .HasMaxLength(500);

        builder.Property(r => r.Capacity)
            .IsRequired();

        builder.Property(r => r.IsActive)
            .IsRequired();

        builder.HasMany(r => r.Meetings)
            .WithOne(m => m.MeetingRoom)
            .HasForeignKey(m => m.MeetingRoomId)
            .OnDelete(DeleteBehavior.SetNull);
    }
}
